// /src/mock/users.js
let users = JSON.parse(localStorage.getItem('mock-users')) || [
  {
    studentID: '2023211180',
    username: '测试用户',
    password: '123456',
    userId: 1,
    avatar: 'https://example.com/avatar1.jpg',
    likedDiaries: [1,2,3]
  },
  
]

// 获取所有用户
export const getUsers = () => users

// 添加新用户
export const registerUser = (userData) => {
  if (users.some(u => u.studentID === userData.studentID)) {
    throw new Error('该学号已注册')
  }
  
  const newUser = {
    ...userData,
    userId: Date.now(),
    username: userData.studentID, // 默认用户名设为学号
    avatar: userData.avatar || 'https://example.com/default-avatar.jpg',
    likedDiaries: [], //点赞列表
  }
  
  users = [...users, newUser]
  localStorage.setItem('mock-users', JSON.stringify(users))
  return newUser
}

// 根据学号查找用户
export const findUserByStudentID = (studentID) => {
  return users.find(u => u.studentID === studentID)
}